if "导入sys.path":
    import sys
    sys.path.append(r"F:\A_RuanJian\Py_project\pro_test")
    sys.path.append(r"F:\A_RuanJian\Py_project\pro_test\zQuicker")
    # path.append 一定要放在开头
if "导入其他":
    from flask import Flask, request, jsonify
    import logging
    from QuickerBeta.qk_python import *
    from QuickerBeta.qk_comple import AutoComple
    from base.util import proc_search

    # 不打印普通消息
    log = logging.getLogger('werkzeug')
    log.setLevel(logging.ERROR)
    # log.setLevel(logging.INFO)
    app = Flask(__name__)


@app.route('/post', methods=['POST'])
def post():
    if "获取参数":
        keyCode = request.form.get("keyCode")
        operate = request.form.get("operate")
        name = request.form.get("name")
        val = request.form.get("val")
        version = request.form.get("version")
        text = request.form.get("text")
        code = request.form.get("code") or request.form.get("exec")
        vars_q = request.form.get("vars_q")
        OriList: str = request.form.get("OriList")
        procName = request.form.get("procName")

    if operate:  # 全局变量管理
        return globals_operate(operate, name, val)
    if OriList:  # 补全#
        # cc(procName)
        self_ = AutoComple(OriList, procName)
        resp = self_.run()
        return jsonify(resp)
    if keyCode:  # 对符
        return jsonify(keyCodeCheck(keyCode)())
    if code:  # 执行代码
        res = CodeExec().main(code, version, vars_q)
        # print(res)
        return jsonify(res)

    if text:
        # 测试用
        return jsonify(text)


if __name__ == "__main__":
    # 防止端口冲突
    port = 5002
    proc_search(port, killall=1)
    # 实现持久连接, 但也多了更多验证规则。
    # WSGIRequestHandler.protocol_version = 'HTTP/1.1'
    app.config['JSON_AS_ASCII'] = 0  # unicode显示为中文
    app.run(debug=0, host='127.0.0.1', port=port)

"""
访问主页：
127.0.0.1:5000
直接访问路由：
127.0.0.1:5000/get
"""
